package com.lesson17.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lesson17.model.StudentModel;

@RestController
public class StudentController {
	
	private Map<Integer, StudentModel> stus = new HashMap<>();
	
	@RequestMapping(value={"/stu/addStudent"}, consumes="application/xml;charset=UTF-8")
	public Map<String, Object> addStudent(@RequestBody StudentModel studentModel){
		 Map<String, Object> results = new HashMap<String, Object>();
		 results.put("code", "000000");
		 results.put("msg", "success");
		 stus.put(studentModel.getId(), studentModel);
		 System.out.println("UserName = "+studentModel.getUserName());
		 return results; 
	}
	
	@RequestMapping(value={"/stu/getStudent"}, produces="application/xml;charset=UTF-8", consumes="application/xml;charset=UTF-8")
	public StudentModel getStudent(@RequestBody StudentModel studentModel){
		 System.out.println(stus);
		 return stus.get(studentModel.getId()); 
	}

}
